<?php

class Default_Form_Comment extends Zend_Form {
	
	const ENCODING               = 'UTF-8';
	const FULLNAME_MIN_LENGTH    = 0;
	const FULLNAME_MAX_LENGTH    = 50;
	const CONTENT_MIN_LENGTH 	 = 300;
	const CONTENT_MAX_LENGTH 	 = 500;
	
	public function init() {
		
		$this->setName('frmComment');
		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');
		
		// Full name
        $fullname = self::addFullName();
		
		// Content
		$content = self::addContent();
		
		$this->addElements(array($fullname, $content));
	}

	/*
	 * Add full_name element
	 */
	protected  function addFullName() {
		$fullnameAlpha = new Zend_Validate_Alpha(true);
        //Length validate
        $fullnameLength = new Zend_Validate_StringLength(self::FULLNAME_MIN_LENGTH, self::FULLNAME_MAX_LENGTH, self::ENCODING);
        $fullname = new Zend_Form_Element_Text('ho_ten');
        $fullname	->addFilter('StripTags')
        			->addFilter('StringTrim')
        			->addValidator($fullnameLength)
        			->addValidator($fullnameAlpha)
        			->setDecorators(array('ViewHelper'));
        return $fullname;
	}

	/*
	 * Add title element
	 */
	protected  function addContent() {
		$contentAlpha = new Zend_Validate_Alpha(true);
        //Length validate
        $contentLength = new Zend_Validate_StringLength(self::CONTENT_MIN_LENGTH, self::CONTENT_MAX_LENGTH, self::ENCODING);
        $content = new Zend_Form_Element_Textarea('noi_dung');
        $content->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->addValidator($contentLength)
        		->addValidator($contentAlpha)
        		->setDecorators(array('ViewHelper'));
        
        return $content;
	}
}